import Vue from 'vue'
import myHeader from '../../components/Header';
import myFooter from '../../components/Footer';
import centerHeader from '../../components/center-header';
export default {
  components: {
    myHeader,
    myFooter
  },
  data() {
    return {
      header: [
        { title: "订单管理", path: "/home/order"},
      ],
      data1:[],//查询数据
      data2:[],//全部
      data3:[],//存储查找订单号数据
      checkedMsg: 3,
      informationActiveName:'first',
      pickerOptions2: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      value7: '',
      moreInfo:'加载更多..',
      d_id:'',
      showMore1:true,
      showMore2:true,
      showMore3:true,
      showMore4:true,
      searchOrder:'',//输入要查询的单号
      //加载更多
      parameter: {
        page: 1,
        limit: 10,
        d_id: '',
      },
      parameter1: {
        page: 1,
        limit: 10,
        d_id: '',
        status:0
      },
      parameter2: {
        page: 1,
        limit: 10,
        d_id: '',
        status:1
      },
      parameter3: {
        page: 1,

        limit: 10,
        d_id: '',
        status:2
      },
    }
  },
  components: {
    centerHeader
  },
  methods: {
    clear(value7){
      if(!value7){
        this[this.informationActiveName]();
      }
    },
    //检查处理状态库
    //1.检查充值来源参数
    checkpay_source_type(type) {
      if (type == 0) {
        return '未知'
      } else if (type == 1) {
        return '推广'
      } else if (type == 2) {
        return '活动'
      }
    },
    //2.检查充值状态
    checkpay_status(type){
      if (type == 0) {
        return '待支付'
      } else if (type == 1) {
        return '已支付'
      } else if (type == 2) {
        return '已关闭'
      }
    },
    //格式化时间
    format(time){
      time=new Date(time);
      time=time.getFullYear() + '-' + (time.getMonth() + 1) + '-' + time.getDate();
      return time;
    },
    //日期查询功能
    search(informationActiveName,value7){
      let that=this;
      let num='';
      if(informationActiveName=="first"){
        num=-1;
        that.showMore1=true;
        that.parameter.page=1;
      }else if(informationActiveName=="second"){
        num=0;
        that.showMore2=true;
        that.parameter1.page=1;
      }else if(informationActiveName=="third"){
        num=1;
        that.showMore3=true;
        that.parameter2.page=1;
      }else if(informationActiveName=="fourth"){
        num=2;
        that.showMore4=true;
        that.parameter3.page=1;
      }
      if(typeof(value7)=="undefined"||value7==null||value7==""||value7==0){
        alert("请选择时间！");
      }else{
        let start=that.format(value7[0]);
        let end=that.format(value7[1]);
        that.axios.post('/cp/v1/manage/getIndex',{
          d_id:that.d_id,
          start:start,
          end:end,
          status:num
        })
          .then(function (res) {
            that.data1.splice(0,that.data1.length);
            that.data1.push(res.data.data);
            that.data2=res.data.data.tot;
          })
          .catch(function (err) {
            console.log(err)
          })
      }
    },
    //订单查询功能
    search1(searchOrder){
      let that=this;
      that.axios.post('/cp/v1/manage/getIndex',{
        d_id:that.d_id,
        seach:searchOrder
      })
        .then(function (res) {
          if(res.data.code==200){
            that.data2=res.data.data.tot;
            that.showMore1=false;
            that.showMore2=false;
            that.showMore3=false;
            that.showMore4=false;
          }
        })
        .catch(function (err) {
          console.log(err);
        })
    },
    //tab切换执行相应方法
    handleClick(tab, event) {
      this[tab.name] && this[tab.name]();
      this.parameter.page=1;
      this.parameter1.page = 1;
      this.parameter2.page = 1;
      this.parameter3.page = 1;
      this.parameter.start = "";
      this.parameter.end = "";
      this.parameter1.start = "";
      this.parameter1.end = "";
      this.parameter2.start = "";
      this.parameter2.end = "";
      this.parameter3.start = "";
      this.parameter3.end = "";

    },
    //获取全部订单信息
    getAll(){
      let that=this;
      that.data1.splice(0,that.data1.length);
      that.axios.post('/cp/v1/manage/getIndex',{
        d_id:that.d_id,
        page:1,
        limit:10
      })
        .then(function (res) {
          that.data1.push(res.data.data);
          that.data2=res.data.data.tot;
        })
        .catch(function (err) {
          console.log(err);
        })
    },
    //first
    first(){
      let that=this;
      that.showMore1=true;
      that.parameter.page = 1;
      that.value7="";
      that.data1.splice(0,that.data1.length);
      that.axios.post('/cp/v1/manage/getIndex',{
        d_id:that.d_id,
        page:1,
        limit:10
      })
        .then(function (res) {
          that.data1.push(res.data.data);
          that.data2=res.data.data.tot;
        })
        .catch(function (err) {
          console.log(err);
        })
    },
    second(){
      let that=this;
      that.showMore2=true;
      that.parameter1.page=1;
      that.value7="";
      that.data1.splice(0,that.data1.length);
      that.axios.post('/cp/v1/manage/getIndex',{
        d_id:that.d_id,
        page:1,
        limit:10,
        status:0
      })
        .then(function (res) {
          that.data1.push(res.data.data);
          that.data2=res.data.data.tot;
        })
        .catch(function (err) {
          console.log(err);
        })
    },
    third(){
      let that=this;
      that.showMore3=true;
      that.parameter2.page=1;
      that.value7="";
      that.data1.splice(0,that.data1.length);
      that.axios.post('/cp/v1/manage/getIndex',{
        d_id:that.d_id,
        page:1,
        limit:10,
        status:1
      })
        .then(function (res) {
          that.data1.push(res.data.data);
          that.data2=res.data.data.tot;
        })
        .catch(function (err) {
          console.log(err);
        })
    },
    fourth(){
      let that=this;
      that.showMore4=true;
      that.parameter3.page=1;
      that.value7="";
      that.data1.splice(0,that.data1.length);
      that.axios.post('/cp/v1/manage/getIndex',{
        d_id:that.d_id,
        page:1,
        limit:10,
        status:2
      })
        .then(function (res) {
          that.data1.push(res.data.data);
          that.data2=res.data.data.tot;
        })
        .catch(function (err) {
          console.log(err);
        })
    },
    //获取全部(更多)
    a(value7){
      let that=this;
      console.log(that.parameter);
      if(typeof(value7)=="undefined"||value7==null||value7==""||value7==0){
        that.$utils.loadmore(that, {
            api: '/cp/v1/manage/getIndex',
            parameter: that.parameter,
            oldArr: that.data2
          }, function (res) {
            if(res){
              res.data.data = res.data.data.tot;
            }else{
              that.showMore1=false
            }
          },
          function (arr) {
            that.data2 = arr;
          }
        )
      }
      else{
        that.showMore1=true;
        let start=that.format(value7[0]);
        let end=that.format(value7[1]);
        that.parameter.start = start;
        that.parameter.end = end;
        that.$utils.loadmore(that, {
            api: '/cp/v1/manage/getIndex',
            parameter: that.parameter,
            oldArr: that.data2
          }, function (res) {
            if(res){
              res.data.data = res.data.data.tot;
            }else{
              that.showMore1=false
            }
          },
          function (arr) {
            that.data2 = arr;
          })
      }
    },
    //获取待支付订单信息(更多)
    b(value7){
      let that=this;
      if(typeof(value7)=="undefined"||value7==null||value7==""||value7==0){
        that.$utils.loadmore(that, {
            api: '/cp/v1/manage/getIndex',
            parameter: that.parameter1,
            oldArr: that.data2
          }, function (res) {
            if(res){
              res.data.data = res.data.data.tot;
            }else{
              that.showMore2=false
            }
          },
          function (arr) {
            that.data2 = arr;
          }
        )
      }
      else{
        that.showMore2=true;
        let start=that.format(value7[0]);
        let end=that.format(value7[1]);
        that.parameter1.start = start;
        that.parameter1.end = end;
        that.$utils.loadmore(that, {
            api: '/cp/v1/manage/getIndex',
            parameter: that.parameter1,
            oldArr: that.data2
          }, function (res) {
            if(res){
              res.data.data = res.data.data.tot;
            }else{
              that.showMore2=false
            }
          },
          function (arr) {
            that.data2 = arr;
          })
      }
    },
    // //获取已支付订单信息(更多)
    c(value7){
      let that=this;
      if(typeof(value7)=="undefined"||value7==null||value7==""||value7==0){
        that.$utils.loadmore(that, {
            api: '/cp/v1/manage/getIndex',
            parameter: that.parameter2,
            oldArr: that.data2
          }, function (res) {
            if(res){
              res.data.data = res.data.data.tot;
            }else{
              that.showMore3=false
            }
          },
          function (arr) {
            that.data2 = arr;
          }
        )
      }
      else{
        that.showMore3=true;
        let start=that.format(value7[0]);
        let end=that.format(value7[1]);
        that.parameter2.start = start;
        that.parameter2.end = end;
        that.$utils.loadmore(that, {
            api: '/cp/v1/manage/getIndex',
            parameter: that.parameter2,
            oldArr: that.data2
          }, function (res) {
            if(res){
              res.data.data = res.data.data.tot;
            }else{
              that.showMore3=false
            }
          },
          function (arr) {
            that.data2 = arr;
          })
      }
    },
    // //获取已关闭订单信息(更多)
    d(value7){
      let that=this;
      if(typeof(value7)=="undefined"||value7==null||value7==""||value7==0){
        that.$utils.loadmore(that, {
            api: '/cp/v1/manage/getIndex',
            parameter: that.parameter3,
            oldArr: that.data2
          }, function (res) {
            if(res){
              res.data.data = res.data.data.tot;
            }else{
              that.showMore4=false
            }
          },
          function (arr) {
            that.data2 = arr;
          }
        )
      }
      else{
        that.showMore4=true;
        let start=that.format(value7[0]);
        let end=that.format(value7[1]);
        that.parameter3.start = start;
        that.parameter3.end = end;
        that.$utils.loadmore(that, {
            api: '/cp/v1/manage/getIndex',
            parameter: that.parameter3,
            oldArr: that.data2
          }, function (res) {
            if(res){
              res.data.data = res.data.data.tot;
            }else{
              that.showMore4=false
            }
          },
          function (arr) {
            that.data2 = arr;
          })
      }
    },
    getMore(num,value7){
      let that=this;
      that.num;
    },
  },
  created(){
    let d_id=JSON.parse(localStorage.getItem('userInfo')).user_id;
    console.log(d_id);
    this.d_id=d_id;
    this.parameter.d_id=d_id;
    this.parameter1.d_id=d_id;
    this.parameter2.d_id=d_id;
    this.parameter3.d_id=d_id;
    this.getAll();
  }
}
